import Foundation

// MARK: - 社区分类模型
struct CommunityCategory: Codable, Identifiable {
    let id: String
    let name: String
}

// MARK: - 社区内容模型
struct CommunityNote: Codable, Identifiable {
    let id: String
    let title: String
    let content: String
    let images: [String]
    let video: String?
    let authorId: String
    let authorName: String
    let authorAvatar: String
    let likeNum: Int
    let commentNum: Int
    let shareNum: Int
    let createTime: String
    let userIsLike: Bool
    let categoryId: String?
    let categoryName: String?
    let topicId: String?
    let topicName: String?
    
    enum CodingKeys: String, CodingKey {
        case id, title, content, images, video
        case authorId = "author_id"
        case authorName = "author_name"
        case authorAvatar = "author_avatar"
        case likeNum = "like_num"
        case commentNum = "comment_num"
        case shareNum = "share_num"
        case createTime = "create_time"
        case userIsLike = "user_is_like"
        case categoryId = "category_id"
        case categoryName = "category_name"
        case topicId = "topic_id"
        case topicName = "topic_name"
    }
}

// MARK: - 推荐作者模型
struct RecommendAuthor: Codable, Identifiable {
    let id: String
    let authorId: String
    let authorName: String
    let authorAvatar: String
    let signature: String
    let fansNum: Int
    let noteNum: Int
    let isConcerned: Bool
    let noteImages: [String]
    
    enum CodingKeys: String, CodingKey {
        case id
        case authorId = "author_id"
        case authorName = "author_name"
        case authorAvatar = "author_avatar"
        case signature
        case fansNum = "fans_num"
        case noteNum = "note_num"
        case isConcerned = "is_concerned"
        case noteImages = "note_images"
    }
}

// MARK: - API响应模型
struct CommunityListResponse: Codable {
    let list: [CommunityNote]
    let totalPage: Int
    let currentPage: Int
    
    enum CodingKeys: String, CodingKey {
        case list
        case totalPage = "total_page"
        case currentPage = "current_page"
    }
}

struct RecommendAuthorResponse: Codable {
    let list: [RecommendAuthor]
    let totalPage: Int
    let currentPage: Int
    
    enum CodingKeys: String, CodingKey {
        case list
        case totalPage = "total_page"
        case currentPage = "current_page"
    }
}

// MARK: - 社区页面状态模型
struct DiscoverPageState {
    var selectedTab: Int = 1 // 1: 发现, 0: 关注
    var selectedCategoryId: String = ""
    var selectedCategoryIndex: Int = 0
    var categories: [CommunityCategory] = []
    var discoverNotes: [String: [CommunityNote]] = [:] // categoryId -> notes
    var followNotes: [CommunityNote] = []
    var recommendAuthors: [RecommendAuthor] = []
    var isLoading: Bool = false
    var isRefreshing: Bool = false
    var hasMoreData: Bool = true
    var currentPage: Int = 1
}

// MARK: - 瀑布流项目模型
struct WaterfallItem: Identifiable {
    let id = UUID()
    let note: CommunityNote
    let height: CGFloat
}